package cn.edu.gdgm.system.controller;

import cn.edu.gdgm.system.dto.RestResult;
import cn.edu.gdgm.system.dto.RestResultType;
import cn.edu.gdgm.system.exception.WeChatUserClientException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(MissingServletRequestParameterException.class)
    public ResponseEntity<RestResult<String>> error(MissingServletRequestParameterException exception) {
        RestResult<String> body = RestResult.error(RestResultType.REQUEST_PARAMETER, exception.getMessage());
        return ResponseEntity.badRequest().body(body);
    }

    @ExceptionHandler(WeChatUserClientException.class)
    public ResponseEntity<RestResult<String>> error(WeChatUserClientException exception) {
        RestResult<String> body = RestResult.error(RestResultType.REQUEST_PARAMETER, exception.getMessage());
        return ResponseEntity.badRequest().body(body);
    }
}
